
#ifndef _RADIX_ENGINE_IMPL_RENDER_H_
#define _RADIX_ENGINE_IMPL_RENDER_H_

#include <Engine/Render.h>
#include <d3d11.h>

_BeginNamespace(Radix)
_BeginNamespace(Engine)
_BeginNamespace(Component)
_BeginNamespace(Direct3D)

/*
=================================================================
== Geometry
=================================================================
*/
class Geometry :public IGeometry
{
public:
	Geometry(ID3D11Buffer* vertexBuffer, ID3D11Buffer* indexBuffer);
	virtual ~Geometry();

private:
	ID3D11Buffer* mVertexBuffer;
	ID3D11Buffer* mIndexBuffer;
};
/*
=================================================================
== RenderObject
=================================================================
*/
class RenderObject :public IRenderObject
{
public:
	RenderObject(const Matrix4x4& t, const IGeometry& g, const IMaterial& m);
	virtual ~RenderObject();

public:
	virtual const Matrix4x4& transform();
	virtual void transform(const Matrix4x4& t);
	virtual const IGeometry& geometry();
	virtual void geometry(const IGeometry& g);
	virtual const IMaterial& material();
	virtual void material(const IMaterial& m);

private:
	Matrix4x4 mTransform;
	IGeometry mGeometry;
	IMaterial mMaterial;
};
/*
=================================================================
== RenderSystem
=================================================================
*/
class RenderSystem :public IRenderSystem
{
	typedef std::list<IRenderObject> RenderObjectList;

public:
	RenderSystem();
	virtual ~RenderSystem();

public: // Implements IComponent
	virtual const String& name();
	virtual bool init(const StringValueMap& params);
	virtual void exit();

public: // Implements IRenderSystem
	virtual IGeometry* createGeometry(const Mesh& mesh);
	virtual void dispatchObject(const IRenderObject& object);
	virtual void renderFrame(real elapsed);

private:
	UINT translateCpuAccess(RenderResourceCpuAccess cpuAccess);
	D3D11_USAGE translateUsage(RenderResourceUsage usage);

private:
	ID3D11Device* mDevice;
	ID3D11DeviceContext* mImmContext;
	IDXGISwapChain* mSwapChain;
	ID3D11RenderTargetView* mRenderTargetView;

	RenderObjectList mRenderObjects;
};

_EndNamespace(Direct3D)
_EndNamespace(Component)
_EndNamespace(Engine)
_EndNamespace(Radix)

#endif//_RADIX_ENGINE_IMPL_RENDER_H_
